package library

import (
	"github.com/gogf/gf/v2/database/gdb"
)

/*
@Time : 2023/4/28 11:18
@Author : 56766
@File : mysqlCacheForPower.go
*/

type MysqlCache struct {
	db gdb.DB
}

/*
func (m *MysqlCache) Get(key string, defaultValue interface{}) (ptrValue interface{}, err error) {

	result, err := m.db.Table("wechat_cache").Where("key", key).Fields("value").One()
	if err != nil {
		if err == sql.ErrNoRows {
			return "", cache.ErrCacheMiss
		}
		return "", err
	}
	return result["value"].String(), nil
}
func (m *MysqlCache) Set(key string, value interface{}, expires time.Duration) error {
	data := gdb.Map{
		"key":        key,
		"value":      value,
		"expired_at": time.Now().Add(ttl).Unix(),
	}
	_, err := m.db.Table("wechat_cache").Data(data).Replace()
	return err
}
func (m *MysqlCache) Has(key string) bool {
	_, err := m.db.Table("wechat_cache").Where("key", key).Delete()
	return err
}
func (m *MysqlCache) AddNX(key string, value interface{}, ttl time.Duration) bool {
	data := gdb.Map{
		"key":        key,
		"value":      value,
		"expired_at": time.Now().Add(ttl).Unix(),
	}
	_, err := m.db.Table("wechat_cache").Data(data).Replace()
	return err
}
func (m *MysqlCache) Add(key string, value interface{}, ttl time.Duration) (err error) {
	data := gdb.Map{
		"key":        key,
		"value":      value,
		"expired_at": time.Now().Add(ttl).Unix(),
	}
	_, err := m.db.Table("wechat_cache").Data(data).Replace()
	return err
}
func (m *MysqlCache) Remember(key string, ttl time.Duration, callback func() (interface{}, error)) (obj interface{}, err error) {
	_, err := m.db.Table("wechat_cache").Where("key", key).Delete()
	return err
}
*/
